package short_semester.questionnaire_planet.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import short_semester.questionnaire_planet.request.editRequest.EditFillBlankQuestionBody;

import javax.persistence.*;

@Entity
@Table
@Data
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@NoArgsConstructor
public class FillBlankQuestion {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private Questionnaire questionnaire;

    @Column
    private String title = "";

    @Column
    private String description = "";

    // 是否必答
    @Column
    private Boolean isNecessary = true;

    @JsonIgnore
    @Column
    private Integer sequence;
    
    @Column     //默认值
    private String defaultValue = "";

    @Column
    private Integer count = 0;

    //子类型打卡
    private String qtype = null;
    
    @Transient
    private String type = "completion";
    
    //考试填空特殊属性
    private Integer grade = 0;
    private String resolution = "";
    private String correctAnswer = "";
    
    //关联逻辑
    private String logic = "且";

    private String relationString;
    @Transient
    private Boolean isShow = true; 
    
    public void setValueFrom(EditFillBlankQuestionBody body){
        title = body.getTitle();
        description = body.getDescription();
        isNecessary = body.getIsNecessary();
        defaultValue = body.getDefaultValue();
        grade=body.getGrade();
        resolution=body.getResolution();
        correctAnswer=body.getCorrectAnswer();
    }
    
    public FillBlankQuestion(FillBlankQuestion question){
        title = question.getTitle();
        description = question.getDescription();
        isNecessary = question.getIsNecessary();
        defaultValue = question.getDefaultValue();
        sequence = question.getSequence();
        
        qtype=question.getQtype();
        
        grade=question.getGrade();
        resolution=question.getResolution();
        correctAnswer=question.getCorrectAnswer();
    }

    public FillBlankQuestion(String qtype) {
        this.qtype = qtype;
    }
}
